﻿$(function () {

    $('.description').dotdotdot();

    $('#view-property-from-get-all-container').on('shown', function () {
        google.maps.event.trigger(map, "resize");
    });

    $('#view-property-from-search-container').on('shown', function () {
        google.maps.event.trigger(map, "resize");
    });

    $('#view-property-from-advanced-search-container').on('shown', function () {
        google.maps.event.trigger(map, "resize");
    });

    $('a[href="#advanced-search"]').on('click', function (e) {
        window.activeTab = e.target;
        $('#advanced-search').show();
        $('.description').dotdotdot();
        $('#modal-view-property-from-advanced-search').modal('hide');
    });

    $('a[href="#quick-search"]').on('click', function (e) {
        window.activeTab = e.target;
        window.location.reload(true);
        $('.description').dotdotdot();
        $('#advanced-search').hide();
    });

    $('body').on('click', 'a.pagination-left', function () {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function (result) {
                $('#quick-property-search-results').html(result);
                $('.description').dotdotdot();
            }
        });
        return false;
    });

    $('body').on('click', 'a.pagination-right', function () {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function (result) {
                $('#quick-property-search-results').html(result);
                $('.description').dotdotdot();
            }
        });
        return false;
    });

    $(document.body).on('click', '#close-property-modal', function (e) {
        $('#modal-view-property-from-get-all').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
    });

    $(document.body).on('click', '#btn-create-property-save', function (e) {
        $('#create-residential-property-modal').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        var url = "/Landlords/CreateProperty";
        $.get(url, function (data) {
            $('#landlord-properties').html(data);
        });
    });

    $(document.body).on('click', '#btn-edit-property-save', function () {
        $('#edit-property').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        var url = "/Landlords/GetLandlordProperties";
        $.get(url, function (data) {
            $('#landlord-properties').html(data);
        });
    });

    $(function () {
        $(document.body).on('click', '#btn-edit-landlord-details', function (e) {
            $('#edit-landlord-profile-details').modal('hide');
            $('body').removeClass('modal-open');
            $('.modal-backdrop').remove();
            window.location.reload(true);
            //var url = "/Landlords/EditLandlordDetails";
            //$.get(url, function (data) {
            //    $('#landlord-details').html(data);
            //});
        });
    });

    $(document.body).on('click', '#show-create-property-modal, #show-create-another-property-modal', function (e) {
        var url = $('#create-residential-property-modal').data('url');
        $.get(url, function (data) {
            $('#create-property-container').html(data);
            $('#create-residential-property-modal').modal('show');
        });
    });

    $(document.body).on('click', '.view', function (e) {
        var url = "/ResidentialProperties/ViewProperty";
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#view-property-container').html(data);
            $('#view-property').modal('show');
        });
    });

    $(document.body).on('click', '.edit', function (e) {
        var url = "/ResidentialProperties/EditProperty";
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#edit-property-container').html(data);
            $('#edit-property').modal('show');
        });
    });

    $(document.body).on('click', '.upload', function (e) {
        var url = "/Landlords/UploadPropertyPhoto";
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#upload-photo-container').html(data);
            $('#upload-photo').modal('show');
        });
    });




    $(document.body).on('click', '.show-modal', function () {
        var url = $('#edit-landlord-profile-details').attr('data-url');
        $.get(url, function (data) {
            $('#edit-landlord-details-container').html(data);
            $('#edit-landlord-profile-details').modal('show');
        });
    });




    $(document.body).on('click', '.show-modal', function () {
        var url = $('#modal-view-property-from-search').attr('data-url');
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#view-property-from-search-container').html(data);
            $('#modal-view-property-from-search').modal('show');
        });
    });

    $(document.body).on('click', '.show-modal', function (e) {
        var url = $('#modal-view-property-from-advanced-search').attr('data-url');
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#view-property-from-advanced-search-container').html(data);
            $('#modal-view-property-from-advanced-search').modal('show');
        });
    });

    $(document.body).on('click', '.show-modal', function (e) {
        var url = $('#modal-view-property-from-get-all').attr('data-url');
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#view-property-from-get-all-container').html(data);
            $('#modal-view-property-from-get-all').modal('show');
        });
    });

    $(document.body).on('click', '.show-modal', function () {
        var url = $('#modal-view-property-from-search').attr('data-url');
        var id = $(this).attr('data-id');

        $.get(url + '/' + id, function (data) {
            $('#view-property-from-search-container').html(data);
            $('#modal-view-property-from-search').modal('show');
        });
    });

    $(document.body).on('click', '.show-tenant-modal', function (e) {
        var url = "/Tenants/ViewProfile";
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#view-tenant-profile-container').html(data);
            $('#modal-view-tenant-profile').modal('show');
        });
    });

    $(document.body).on('click', '#show-edit-tenant-details-modal', function () {
        var url = $('#edit-tenant-personal-details').data('url');
        $.get(url, function (data) {
            $('#container').html(data);
            $('#edit-tenant-personal-details').modal('show');
        });
    });

    $(document.body).on('click', '#btn-save-edit-tenant-details', function () {
        $('#show-edit-tenant-details-modal').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
    });

    $(document.body).on('click', '#showModal', function () {
        var url = $('#create-tenant-group-member-modal').data('url');
        $.get(url, function (data) {
            $('#container').html(data);
            $('#create-tenant-group-member-modal').modal('show');
        });
    });

    $(document.body).on('click', '.edit-member', function (e) {
        var url = "/Tenants/EditMember";
        var id = $(this).attr('data-id');
        $.get(url + '/' + id, function (data) {
            $('#edit-member-container').html(data);
            $('#edit-member').modal('show');
        });
    });

    $(document.body).on('click', '#show-edit-tenant-property-attributes-modal', function () {
        var url = $('#edit-tenant-property-attributes').data('url');
        $.get(url, function (data) {
            $('#container_2').html(data);
            $('#edit-tenant-property-attributes').modal('show');
        });
    });

    $(document.body).on('click', '#btn-save-edit-tenant-attributes', function () {
        $('#show-edit-tenant-property-attributes-modal').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
    });

    $(document.body).on('click', '.add-tgm', function (e) {
        var url = "/Tenants/TenantGroupMembers";
        $.get(url, function (data) {
            $('#container').html(data);
            $('#create-tenant-group-member-modal').modal('show');
        });
    });

    $(document.body).on('click', '#add-another-reference', function () {
        var url = $('#add-another-reference-modal').data('url');
        $.get(url, function (data) {
            $('#add-another-reference-container').html(data);
            $('#add-another-reference-modal').modal('show');
        });
    });

    $(document.body).on('click', '#btn-close-add-reference', function () {
        var url = "/Tenants/TenantUploadReference";
        $.get(url, function (data) {
            $('#tenant-reference-photos').html(data);
        });
    });

    $(document.body).on('click', '.show-modal', function (e) {
        var url = "/Tenants/TenantUploadReference";
        $.get(url, function (data) {
            $('#add-reference-container').html(data);
            $('#add-reference').modal('show');
        });
    });

    function onAjaxSuccess(data, status, xhr) {
        if (data.error) {
            $.notify({
                type: "error",
                text: data.message
            });
        }
        else {
            $('.modal').modal('hide');
        }
    }

});


